
import UIKit

extension UIBarButtonItem {
    
    // 创建 UIBarButtonItem
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let button:UIButton = UIButton(type: .custom)
        button.frame = CGRect(x:0, y:0, width:50, height:30)
        button.setTitle(title, for:.normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        if isBack {
            let imageName = "navigationbar_back_withtext"
            button.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            button.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        }
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: button)
    }
}
